{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def get_list_of_files(address):\n",
    "    \n",
    "    files = glob.glob(os.path.join(address,\"*_CLS.txt\"))\n",
    "    return sorted(files)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "files1=get_list_of_files('/data/Public Data/IEEE Data Fusion Contest 2019/DFC2019_track4_trainval/Train-Track4/111')\n",
    "files2=get_list_of_files('/data/Public Data/IEEE Data Fusion Contest 2019/DFC2019_track4_trainval/Train-Track4/222')\n",
    "files3=get_list_of_files('/data/Public Data/IEEE Data Fusion Contest 2019/DFC2019_track4_trainval/Train-Track4/333')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "for i in range(len(files1)):\n",
    "    \n",
    "    label1=np.array(pd.read_csv(files1[i],sep=',',header=None))\n",
    "    label2=np.array(pd.read_csv(files2[i],sep=',',header=None))\n",
    "    label3=np.array(pd.read_csv(files3[i],sep=',',header=None))\n",
    "    label_mat=np.concancate([label1,label2,label3],axis=1)\n",
    "    \n",
    "    vote_label=[]\n",
    "    for j in range(label_mat.shape[0]):\n",
    "        vote_label.append(np.argmax(np.bincount(label_mat[j,:])))\n",
    "\n",
    "    path,labelfilename=os.path.split(files1[i])\n",
    "    outputlabelpath='/vote_result_address/'+labelfilename\n",
    "    \n",
    "    dt_label=pd.DataFrame(vote_label)\n",
    "    dt_label.to_csv(outputlabelpath,sep=',',header=None,index=False)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python (py4torch_tf)",
   "language": "python",
   "name": "pytorch"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.6"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
